//
//  NSDictionary+LLHelper.m
//  LLFoundation
//
//  Created by my_liu on 2016/11/14.
//  Copyright © 2016年 . All rights reserved.
//

#import "NSDictionary+LLHelper.h"

@implementation NSDictionary (LLHelper)

- (NSDictionary *)toNoNullNo0Dictionary
{
    NSMutableDictionary *dict = [NSMutableDictionary dictionary];
    
    for (NSString *key in [self allKeys]) {
        
        if ([[self objectForKey:key] isEqual:[NSNull null]]) {
            continue;
        }
        
        if ([[self objectForKey:key] isEqualToNumber:[NSNumber numberWithInteger:0]]) {
            continue;
        }
        
        [dict setObject:[self objectForKey:key] forKey:key];
        
    }
    
    return [NSDictionary dictionaryWithDictionary:dict];
}

- (NSString *)n_ToString
{
    NSError *error = nil;
    NSData *data  = [NSJSONSerialization dataWithJSONObject:self options:NSJSONWritingPrettyPrinted error:&error];
    if (!error) {
        
        NSString *jsonString = [[NSString alloc] initWithData:data
                                                     encoding:NSUTF8StringEncoding];
        return jsonString;
    }
    else
    {
        return nil;
    }
}

@end
